import { mainWindow } from '../..'
import SimulationSpeed from '../core/SimulationSpeed'

export type MsgType = 'product' | 'simTime' | 'agv' | 'style' | 'workerPool'
export type MsgState =
  | null
  | 'generate'
  | 'move'
  | 'transport'
  | 'recycle'
  | 'startProcessing'
  | 'finishProcessing'
  | 'change'

/**
 * 产品 product [generate,move,recycle]
 *
 * 缓冲区 buffer [change]
 */
export const messageTransfer = (type: MsgType, state: MsgState, parameter: any): void => {
  const payload = { type, state, parameter }
  if (state === 'move') {
    payload.parameter = {
      duration: 300 / SimulationSpeed.getSpeed,
      ...payload.parameter
    }
  }
  mainWindow.webContents.send('simulationData', payload)
}
